package com.lantu.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;


import com.lantu.sys.entity.Teacher;
import com.lantu.sys.mapper.TeacherMapper;
import com.lantu.sys.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {

    @Autowired
    TeacherMapper teacherMapper;

    @Override
    public Teacher getByTeacherById(Integer userTno) {
        QueryWrapper<Teacher> queryWrapper=new QueryWrapper<Teacher>();
        queryWrapper.eq("tno",userTno);
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public IPage<Teacher> getTeachersByOpr(Page<Teacher> paraParam, Teacher teacher) {
        QueryWrapper queryWrapper =new QueryWrapper();
        if (!StringUtils.isEmpty(teacher.getName())){
            queryWrapper.like("name",teacher.getName());
        }
        if (!StringUtils.isEmpty(teacher.getZhicheng())){
            queryWrapper.eq("zhicheng",teacher.getZhicheng());
        }
        queryWrapper.orderByDesc("id");

        Page<Teacher> page = baseMapper.selectPage(paraParam, queryWrapper);
        return page;

    }

    @Override
    public List<Teacher> getAllTeacherCounts() {
        return teacherMapper.getAllTeacherCounts();
    }

    @Override
    public List<Teacher> getzhicheng() {
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.groupBy("zhicheng");
        return teacherMapper.selectList(teacherQueryWrapper);
//        return null;
    }

    @Override
    public List<Teacher> getlist() {
        QueryWrapper<Teacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.select("zhicheng");
        return teacherMapper.selectList(teacherQueryWrapper);
    }


}
